from django.shortcuts import render_to_response
import datetime
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from ktit.soft.models import Catalog
from forms import CatalogForm
from forms import FileprogForm
from models import Fileprog

#def current_datetime(request):
    #now = datetime.datetime.now()
    #t = get_template('current_datetime.html')
    #html = t.render(Context({'current_date': now}))
    #return HttpResponse(html)
    #current_date = datetime.datetime.now()
    #return render_to_response('current_datetime.html', locals())

#@login_required
def index(request):
	#return render_to_response('admin/index.html', {'title': _('Site administration')}, context_instance=template.RequestContext(request))
	#if request.user.is_authenticated():
	res = Catalog.objects.filter(parent=1)
	current_date = datetime.datetime.now()
	return render_to_response('soft/index.html', locals())


def addcatalog(request):
    if request.method == 'POST':
        form = CatalogForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('ok/')
    else:
        form = CatalogForm()
    return render_to_response('soft/form_catalog_add.html', locals())


def addfile(request):
    if request.method == 'POST':
        form = FileprogForm(request.POST, request.FILES)
        if form.is_valid():

            #instance = Fileprog() 
            #instance.uploaded_by = request.user 
            #save_instance(form, instance) 
            #request.user.message_set.create(message=_('Your file has been received.')) 



            form.save()
            return HttpResponseRedirect('ok/')



     

    else:
        #file_data = {'file': {'filename':'face.jpg', 'content': 'file data'}}file_data

        form = FileprogForm()
    return render_to_response('soft/form_file_add.html', locals())